using System;
using System.Web.UI;
using System.IO;

namespace SoftwareMonkeys.Scriptech.Scripts
{
	public partial class BaseScript : System.Web.UI.UserControl//System.Web.Mvc.ViewPage
	{		
		public ScriptProcess CurrentProcess = null;
		
		public HtmlTextWriter OutputWriter = null;
		
		public bool Raw =  false;
		
		private string heading = String.Empty;
		public string Heading
		{
			get { return heading; }
			set { heading = value; }
		}
	
		private Console console;
		public Console Console
		{
			get {
				return console;
			}
		}
		
		public BaseScript ()
		{
		}
		
		protected override void OnInit (EventArgs e)
		{
			Response.ContentType = "text/html";
			
			Server.ScriptTimeout = 60 * // minutes
				60 * // seconds
					1000; // milliseconds
			
			base.OnInit (e);
		}
		
		protected override void OnLoad (EventArgs e)
		{
			base.OnLoad (e);
			
			
		}
		
		// TODO: Remove if not needed
		/*public string GetProjectDirectory(string projectName)
		{
			
			string path = Server.MapPath("/");
			throw new Exception(path);
		}*/
		
		protected override void Render (HtmlTextWriter writer)
		{
			PrepareConsole(writer);
			
			base.Render (writer);
		}
		
		public void PrepareConsole(TextWriter writer)
		{
			console = new SoftwareMonkeys.Scriptech.Scripts.Console(new ConsoleWriter(this, writer));
		}
	}
}

